package com.github.llyb120.calengine;

import cn.hutool.core.util.ArrayUtil;
import com.github.llyb120.calengine.parser.AbstractParser;
import com.github.llyb120.calengine.parser.GeneratorParser;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;

public class App {

//    @Option(generator = "-userId", required = false, usage = "用户id")
//    private String userId;

    @Option(name = "-generate", required = false, usage = "生成器")
    private String generate;

    public static void main(String[] args) throws Exception {
        if(args.length == 0){
            return;
        }
        String mode = args[0];
//        if(!mode.startsWith("-")){
//            args = ArrayUtil.addAll(
//                    new String[]{"-" + args[0], "true"},
//                    ArrayUtil.sub(args, 1, args.length)
//            );
//            System.out.println(args);
//        }
        App runner = new App();
        CmdLineParser parser = new CmdLineParser(runner);
        parser.printUsage(System.out);
        parser.parseArgument(new String[]{args[0], "true"});
        if (runner.generate.equals("true")) {
            AbstractParser gen = new GeneratorParser();
            gen.parse(ArrayUtil.sub(args, 1, args.length));
        }
//        App runner = new App();
//        CmdLineParser parser = new CmdLineParser(runner);
//        try {
//            parser.parseArgument(args);
//            if(args.length == 0){
//                parser.printUsage(System.out);
//                return;
//            }
//            System.out.println(runner);
////            runner.output();
//        } catch (Exception e) {
//            System.err.println(e.getMessage());
//        }
    }

}
